import { OperationType } from '../../shared/enum';
import {
  Entity,
  PrimaryGeneratedColumn,
  Column,
  CreateDateColumn,
  UpdateDateColumn,
} from 'typeorm';

@Entity('verification_history')
export class VerificationHistory {
  @PrimaryGeneratedColumn()
  id: number;

  @Column({ name: 'username', comment: '与操作关联的用户名' })
  username: string;

  @Column({ name: 'operation_type', comment: '生成验证码的操作类型' })
  operationType: OperationType;

  @Column({ name: 'verification_code', comment: '验证码的实际值' })
  verificationCode: string;

  @Column({ name: 'expires_at', comment: '验证码过期时间戳' })
  expiresAt: string;

  @Column({
    name: 'is_used',
    default: false,
    comment: '标志验证码是否已被使用',
  })
  isUsed: boolean;

  @Column({
    name: 'ip_address',
    nullable: true,
    comment: '执行操作的用户 IP 地址',
  })
  ipAddress: string;

  // 定义 created_at 字段
  @CreateDateColumn({
    type: 'timestamp',
    default: () => 'CURRENT_TIMESTAMP(6)',
  })
  created_at: Date;

  @UpdateDateColumn({
    type: 'timestamp',
    default: () => 'CURRENT_TIMESTAMP(6)',
    onUpdate: 'CURRENT_TIMESTAMP(6)',
  })
  updated_at: Date;
}
